<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="org.limp.mine.StringTool"%>
<%@ page import="org.limp.mine.DateTrimmer"%>
<%@ page import="jt.classic.system.ISystem" %>
<%@ page import="jt.classic.system.user.IUser" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%
   String context = jt.classic.system.ISystem.getContextPath();
   
   Map info = (Map)request.getAttribute("info");
   
   List items = (List)info.get("ITEMS");
   
   IUser user = ISystem.getSessionUser(request);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>编辑图片新闻</title>
</head>
<jsp:include page="../head.jsp"></jsp:include>
<script>
   function handleFile(thizz,tp){
      var type = thizz.value.lastIndexOf(".") > 0 ? thizz.value.substring(thizz.value.lastIndexOf(".") + 1,thizz.value.length):"";
      tp.value = type;
   }
   
   var c = <%=(items!=null&&!items.isEmpty()?items.size():0)%>;
   
   function handleAdd(){
       var o = document.getElementById("DragContainer1");
       
       var bindObject = document.createElement("div");
	   bindObject.id = "div_" + c;
	   bindObject.setAttribute("_id",c);
	   bindObject.className = "DragBox";
	   
	   var str = "内容信息 <input type=\"text\" style=\"width:150px;\" name=\"afname_"+c+"\" class=\"box2\" readonly value=\"\" onclick=\"javascript:selinfo('"+c+"');\">";
	   str += "<input type=\"hidden\" id=\"afid_"+c+"\" name=\"afid_"+c+"\" value=\"\">";
	   str += "\n&nbsp;幻灯显示图片 <input type=\"file\" name=\"file1_"+c+"\" value=\"\">";
	   str += "&nbsp;<a href=\"javascript:handleRemove('div_"+c+"');\">删除</a>";
	   
	   bindObject.innerHTML = str;
	   
       o.appendChild(bindObject);
       
       CreateDragContainer(o);
       
       c++;
   }
   
   function handleRemove(id){
       document.getElementById(id).removeNode(true);
   }
   
   function handleRemoveTrue(divid,id){
       if(confirm("确定删除图片新闻")){
	       var url = context + "/app/info.do?method=delslideitem&id=" + id;
	       var result = trim(sendRequest(url));
	       if(result == "1"){
	           document.getElementById(divid).removeNode(true);
	       }else{
	           alert("删除图片新闻失败");
	       } 
       }
   }
   
   function selinfo(c){
       afid = D("afid_" + c);
       afname = D("afname_" + c);
       var url = context + "/app/info.do?method=listinfo4select";
       //dialog(url,true,"选择幻灯片显示新闻",700,400);
       
        var queryPanel = new Ext.Panel({
		layout : 'fit',
		html : '<iframe width="100%" height="100%" frameborder="0" src="'+url+'"></iframe>'
		});
	
		var queryWin = new Ext.Window({
					id : 'queryWin',
					renderTo : Ext.getBody(),
					layout : 'fit',
					closable : true,
					resizable : false,
					width : 700,
					height : 300,
					title : '选择栏目信息',
					// closeAction : 'close',
					plain : true,
					// maximizable : true,
					plain : true,
					modal : true,
					// tbar : ['-', dateBtn, '-', typeBtn],
					items : [queryPanel]
				});
	
		queryWin.show(this);
   }
   
   var afname;
   var afid;
   
   function setinfo(id,name){
       afid.value = id;
       afname.value = name;
       
       Ext.getCmp('queryWin').close();
   }
   
   function resetimg(id,index){
       if(confirm("重新设置新闻显示图片，将先删除原显示图片，确定执行")){
          var rnt = deleteAnnex(id);
          if(rnt == "1"){
             $("imgarea_" + index).innerHTML = "<input type=\"file\" name=\"file1_"+index+"\" value=\"\">";
          }else{
             alert("删除原显示图片失败，无法重新设置新闻显示图片");
          }
       }
   }

   function handleSubmit(){
      if(isblank(document.form1.asname)){
         alert("请定义图片新闻名称");
      }else if(isblank(document.form1.askey)){
         alert("请定义图片新闻KEY");
      }else{
           var o = document.getElementById("DragContainer1");
       
	       var parts = o.getElementsByTagName("div");
	       
	       if(parts.length == 0){
	          alert("请定义显示新闻项");
	       }else{
	          var rnt = true;
	          var countP = "";
	          for(var i=0;i<parts.length;i++){
		          var _id = parts[i].getAttribute("_id");
		          if(isblank(document.getElementById("afid_" + _id))){
		             alert("请选择图片显示新闻");
		             rnt = false;
		             break;
		          }else{
		             createHidden("afsort_" + _id,i);
		             countP += _id + ",";
		          }
	          }
	          
	          if(rnt && confirm("确定提交")){
	             createHidden("countP",countP.substring(0,countP.length - 1));
	             
	                Ext.MessageBox.wait('提交保存过程中...');   
				    Ext.Ajax.request({       
				        //请求地址       
				       url: context + "/app/info.do?method=updateslideinfo",       
				       //提交参数组       
				       fileUpload: true,   
				       form: 'form1',   
				       scope: 'form1',     
				       //成功时回调       
				       success: function(response, options) {       
				           //获取响应的json字符串        
				           Ext.MessageBox.hide();
				           
				           var json = response.responseText;    
		                   var o = Ext.util.JSON.decode(json);
				           
				           if (o.success) {
							   alert("提交保存成功！");
							   document.location = context + '/app/info.do?method=slidelistinfo';
		                   }else{
				               Ext.Msg.alert('提示', '提交保存失败！'); 
				           }                
				       }      
				     }); 
	          }
	       }
      }
   }
</script>
<link href="<%=context %>/app/info/css/dragcontainer.css" rel=stylesheet>
<script src="<%=context%>/app/info/js/dragcontainer.js"></script>
<body onload="init(<%=(items!=null&&!items.isEmpty()?items.size():0)%>);inithelper();">
<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="asid" value="<%=info.get("AS_ID")%>">
<div style="margin-left:15px;margin-top:15px;">
     <input type="button" class="button0" value="增加幻灯新闻" onclick="handleAdd();">
    <input type="button" class="button0" value="提交" onclick="handleSubmit();">
     </div>

<fieldset id="lanmu" style="width:90%;margin-left:15px;">
<legend>图片新闻 - 编辑图片新闻</legend>
<label for="asname">幻灯片名称</label>
    <input type="text" id="asname" name="asname" value="<%=info.get("ASNAME")%>"/> <font color="red" title="必填项"><b>*</b></font>
    <br/>
  <label for="slidetype">幻灯类型</label>
    <input type="text" id="slidetype" name="slidetype" value="<%=info.get("SLIDETYPE")%>"/>
  <br/>
  <label for="askey">标识key</label>
    <input type="text" id="askey" name="askey" value="<%=info.get("ASKEY")%>"/> <font color="red" title="必填项"><b>*</b></font>
    <br/>
 </fieldset> 
 <DIV id="Demo4">
      <DIV class="DragContainer" id="DragContainer1" overClass="OverDragContainer">
      <%
        if(items != null && !items.isEmpty()){
           for(int i=0;i<items.size();i++){
               Map item = (Map)items.get(i);
               String imgurl = (String)item.get("IMG_URL");
               String imgid = (String)item.get("IMG_ID");
      %>
      <div id="div_<%=i%>" _id="<%=i%>" class="DragBox" style="margin-left:15px;">
        内容信息 <input type="text" style="width:150px;" name="afname_<%=i%>" class="box2" readonly value="<%=item.get("IF_TITLE")%>" onclick="javascript:selinfo('<%=i%>');"><input type="hidden" id="afid_<%=i%>" name="afid_<%=i%>" value="<%=item.get("IF_ID")%>">
	   &nbsp;幻灯显示图片 <%if(!imgurl.equals("")){%><span id="imgarea_<%=i%>"><a href="javascript:void(0);" onclick="javascript:viewAnnex('<%=imgid%>');">预览图片</a>&nbsp;<a href="javascript:void(0);" onclick="javascript:resetimg('<%=imgid%>','<%=i%>');">重新定义显示图片</a></span><%}else{%><input type="file" name="file1_<%=i%>" value=""><%}%>&nbsp;<a href="javascript:void(0);" onclick="javascript:handleRemoveTrue('div_<%=i%>','<%=item.get("ASI_ID")%>');">删除</a>
       <input type="hidden" id="asiid_<%=i%>" name="asiid_<%=i%>" value="<%=item.get("ASI_ID")%>">
      </div>
      <%
           }
        }   
      %>
      </DIV>
</DIV>     
</form>
</body>
</html>